var sz_tokenService = function () {

}

$(function () {
    sz_tokenService.refresh();
})

sz_tokenService.refresh = function () {
    var userBean = sz_ConstantsService.getItem($sz_Constants.USER_BEAN);
    var Authorization = JSON.stringify({
        token: userBean.token,
        userId: userBean.userId
    });

    $.ajax({
        type: "POST",
        url: $sz_Config.refreshTokenURL,
        contentType: "application/json", //必须有
        dataType: "json", //表示返回值类型，不必须
        beforeSend: function (request) {
            request.setRequestHeader($sz_Constants.AUTHORIZATION, Authorization);
        },
        // data: "",  //相当于 //data: "{'str1':'foovalue', 'str2':'barvalue'}",
        success: function (result, textStatus, request) {
            const token = request.getResponseHeader($sz_Constants.AUTHORIZATION);
            if (token && token.length > 20) {
                sz_ConstantsService.setItem('tempToken', token);
                var userBean = sz_ConstantsService.getItem($sz_Constants.USER_BEAN);
                userBean.token = token;
                sz_ConstantsService.setItem($sz_Constants.USER_BEAN, userBean);
                sz_ConstantsService.setItem($sz_Constants.REQUEST_TOKEN, token);
            }
        }
    });


    // const newToken: string = res.headers.get('Authorization');
}